package com.test.service.impl;

import com.test.entity.AdminInfo;
import com.test.dao.AdminInfoDao;
import com.test.service.AdminInfoService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 管理员(AdminInfo)表服务实现类
 *
 * @author makejava
 * @since 2022-11-12 11:01:46
 */
@Service("adminInfoService")
public class AdminInfoServiceImpl implements AdminInfoService {
    @Resource
    private AdminInfoDao adminInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AdminInfo queryById(Integer id) {
        return this.adminInfoDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param adminInfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<AdminInfo> queryByPage(AdminInfo adminInfo, PageRequest pageRequest) {
        long total = this.adminInfoDao.count(adminInfo);
        return new PageImpl<>(this.adminInfoDao.queryAllByLimit(adminInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param adminInfo 实例对象
     * @return 实例对象
     */
    @Override
    public AdminInfo insert(AdminInfo adminInfo) {
        this.adminInfoDao.insert(adminInfo);
        return adminInfo;
    }

    /**
     * 修改数据
     *
     * @param adminInfo 实例对象
     * @return 实例对象
     */
    @Override
    public AdminInfo update(AdminInfo adminInfo) {
        this.adminInfoDao.update(adminInfo);
        return this.queryById(adminInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.adminInfoDao.deleteById(id) > 0;
    }

    @Override
    public AdminInfo selectByAdmin(String name, String password) {
        return adminInfoDao.selectByAdmin(name,password);
    }


}
